package com.email.parser;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class connectDb {

	//connect to the database...collect the field names 
	
	
	public static void main(String []args)
	{
		try
		{
		String connectionURL="jdbc:mysql://localhost/emaildb";
		
		// declare a connection by using Connection interface
		Connection connection = null;
		/* declare object of Statement interface that is used for executing sql 
		statements. */
		Statement statement = null;
		// declare a result set that uses as a table for output data from tha table.
		ResultSet rs = null;
		// Load JBBC driver "com.mysql.jdbc.Driver"
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		/* Create a connection by using getConnection() method that takes parameters 
		of string type connection url, user name and password to connect to database.*/
		connection = DriverManager.getConnection(connectionURL, "root", "");
		/* createStatement() is used for create statement object that is used for 
		sending sql statements to the specified database. */
		statement = connection.createStatement();
		// sql query to retrieve values from the secified table.
		String QueryString = "SELECT * from testtable";
		rs = statement.executeQuery(QueryString);
		
		
		while(rs.next())
		{
			System.out.println("Name is :"+rs.getString(2));
		}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	
	
	
}
